/* ================================================================
*   Copyright (C) 2020 All rights reserved.
*
*   文件名称：example.cpp
*   创 建 者：xunmenglong
*   创建日期：2020年12月06日
*   描    述：
*
================================================================ */


#ifndef EXAMPLE_CPP
#define EXAMPLE_CPP

#include "xhashmap.h"

int main(int argc, char ** argv) {
    xhashmap<int, int> user_age;
    int ret = user_age.init(10);
    if (ret != 0) {
        LOG(ERROR) << "xhashmap init fail";
        return -1;
    }

    // set
    ret += user_age.set(10001, 21);
    ret += user_age.set(10002, 22);
    ret += user_age.set(10003, 23);
    ret += user_age.set(10004, 24);
    ret += user_age.set(10005, 25);

    if (ret != 0) {
        LOG(ERROR) << "xhashmap set fail";
        return -1;
    }
    LOG(NOTICE) << "cur_size: " << user_age.size();

    int test_keys[3] = {10002, 78341, 10005};
    for (int i=0; i<3; i++) {
        int test_key = test_keys[i];
        int * age = user_age.get(test_key);
        if (age == NULL) {
            LOG(NOTICE) << test_key << ": not exists";
        } else {
            LOG(NOTICE) << test_key << ": " << *age;
        }
    }

    LOG(NOTICE) << "remove 10002 ...";
    user_age.remove(10002);
    LOG(NOTICE) << "cur_size: " << user_age.size();
    for (int i=0; i<3; i++) {
        int test_key = test_keys[i];
        int * age = user_age.get(test_key);
        if (age == NULL) {
            LOG(NOTICE) << test_key << ": not exists";
        } else {
            LOG(NOTICE) << test_key << ": " << *age;
        }
    }
    return 0;
}

#endif
